package com.service.impl;

import com.constant.Constant;
import com.entity.GoldPoints;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.RecordMapper;
import com.service.RecordService;
import com.vo.UserGpInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 陈忠杰
 * @Date: 2021/06/29/17:14
 * @Description:
 */
@Service
public class RecordServiceImpl implements RecordService {


    @Autowired
    RecordMapper recordMapper;

    public UserGpInfoVO getAllGoldPoints(int pageNo) {
        PageHelper.startPage(pageNo, Constant.PAGE_SIZE_COURSE);
        List<GoldPoints> goldPoints = recordMapper.selAllGoldPointsById();
        PageInfo<GoldPoints> goldPointsPageInfo = new PageInfo<>(goldPoints);

        UserGpInfoVO userGpInfoVO = recordMapper.selSumGoldPointsByUserId();
        userGpInfoVO.setGoldPointsPageInfo(goldPointsPageInfo);
        return userGpInfoVO;
    }

    @Override
    public int insGoldPoints(int userId, int points) {
        Date date = new Date();
        int i = recordMapper.insGoldPoints(userId, points, date);
        return i;
    }

//    @Override
////    public int exChangePoints(int userId,int points) {
////        int i = recordMapper.updPoints(userId, points);
////        return i;
////    }


}
